from django.db import models

# Create your models here.

# 书名  出版社  作者

class Author(models.Model):
    name = models.CharField(max_length=20,verbose_name='作者')

    class Meta:
        verbose_name = '作者表'
        verbose_name_plural = verbose_name
        db_table = 'author'

    def __str__(self):
        return self.name

class Press(models.Model):
    press_name = models.CharField(max_length=20,verbose_name='出版社')

    class Meta:
        verbose_name = '出版社表'
        verbose_name_plural = verbose_name
        db_table = 'press'

    def __str__(self):
        return self.press_name


class Book(models.Model):
    book_name = models.CharField(max_length=20,verbose_name='书名')
    price = models.DecimalField(max_digits=5,decimal_places=2,verbose_name='价格')
    count = models.IntegerField(verbose_name='销量')
    author = models.ForeignKey(to=Author,on_delete=models.CASCADE,verbose_name='所属作者')
    press = models.ForeignKey(to=Press,on_delete=models.CASCADE,verbose_name='所属出版社')

    class Meta:
        verbose_name = '图书表'
        verbose_name_plural = verbose_name
        db_table = 'books'

    def __str__(self):
        return self.book_name








